package com.javaee.wordtree.controller;

import com.javaee.wordtree.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RTopic;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Date 2025/5/17 15:42
 * @Author liuyang2004
 * @Description
 */
@Slf4j
@RestController()
@CrossOrigin("*")
@RequestMapping("/dcc/")
public class DCCController {

    @Resource
    private RTopic dccTopic;

    /**
     * 动态值变更
     * <p>
     * curl http://127.0.0.1:3030/dcc/update_config?key=ifToday&value=1
     */
    @RequestMapping(value = "update_config", method = RequestMethod.GET)
    public Result<Boolean> updateConfig(@RequestParam String key, @RequestParam String value) {
        try {
            log.info("DCC 动态配置值变更 key:{} value:{}", key, value);
            dccTopic.publish(key + "," + value);
            return Result.success();
        } catch (Exception e) {
            log.error("DCC 动态配置值变更失败 key:{} value:{}", key, value, e);
            return Result.error(String.valueOf(201),"动态配置失败");
        }
    }

}
